package com.gzhryc.net_marketing.cloud.business.event;

import com.gzhryc.common.event.AbsDelayHandler;
import com.gzhryc.common.logging.Logger;
import com.gzhryc.net_marketing.cloud.business.dao.db.PayGoodsOrderLog;
import com.gzhryc.net_marketing.cloud.business.services.PayGoodsOrderLogService;

public class PayOrderLogEventHandler extends AbsDelayHandler<PayOrderLogEvent> {

    static Logger log = Logger.getLogger(PayOrderLogEventHandler.class);

    @Override
    public boolean execute(PayOrderLogEvent event) {
        try {
            PayGoodsOrderLog simpleTeamPayOrderLog = PayGoodsOrderLogService.self().getOrAddByTradeNo(event.getTradeNo(), event.getCreateDate());
            if (simpleTeamPayOrderLog != null) {
                if (!PayGoodsOrderLogService.self().addItemList(simpleTeamPayOrderLog, event.getItemList())) {
                    log.error("更新团拼订单{{0}}的日志失败，日志内容：{{1:json}}",event.getTradeNo(), event.getItemList());
                }
            } else {
                log.error("创建团拼订单{{0}}日志失败",event.getTradeNo());
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return true;
    }
}
